from django.test import TestCase
import models

class TagsTestCase(TestCase):
    def test_001(self):
        self.assertEquals(models.TestModel1.objects.all().count(), 0)
        self.assertEquals(models.TestModel2.objects.all().count(), 0)
        self.assertEquals(models.Tag.objects.all().count(), 0)

        m1 = models.TestModel1(some_text='123', tags_text='ku, ku, ku-ku')
        m1.save()  # tags: ku(1), ku-ku(1)

        self.assertEqual(sorted(map(unicode, m1.get_tags())),
                         sorted(['ku (1)', 'ku-ku (1)']))

        self.assertEqual(sorted(map(unicode, models.Tag.objects.all())),
                         sorted(['ku (1)', 'ku-ku (1)']))

        m2 = models.TestModel2(some_text='444', tags_text='ku, bebebe')
        m2.save()

        self.assertEqual(sorted(map(unicode, models.Tag.objects.all())),
                         sorted(['ku (2)', 'ku-ku (1)', 'bebebe (1)']))

        m2.tags_text = 'ku, GCC'
        m2.save()

        self.assertEqual(sorted(map(unicode, models.Tag.objects.all())),
                         sorted(['ku (2)', 'ku-ku (1)', 'gcc (1)']))

        m2.delete()
        self.assertEqual(sorted(map(unicode, models.Tag.objects.all())),
                         sorted(['ku (1)', 'ku-ku (1)']))
